package cn.lcsjsxy.yxc.servlet;

import cn.lcsjsxy.yxc.listener.MyActivationListener;
import cn.lcsjsxy.yxc.listener.SessionBindingListener;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet(value = "/servlet1")
public class Servlet1 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //向应用域中放入数据
        ServletContext application=this.getServletContext();
        application.setAttribute("keyA","valueA");

        HttpSession session=req.getSession();

        SessionBindingListener sbl=new SessionBindingListener();

        session.setAttribute("sbl",sbl);
        session.removeAttribute("sbl");

        MyActivationListener myActivationListener=new MyActivationListener();
        session.setAttribute("lis",myActivationListener);

        //手动销毁session
        session.invalidate();
    }
}
